#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>


#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <QString>
#include <QStringList>

#include <adl_sdk.h>

#define UNKNOWN_DBL_VALUE 0.0;

static void *hdll;
static int adl_main_control_done;
static int *active_amd_adapters;

typedef int (*ADL_MAIN_CONTROL_CREATE)(ADL_MAIN_MALLOC_CALLBACK, int);
typedef int (*ADL_MAIN_CONTROL_DESTROY)();
typedef int (*ADL_ADAPTER_NUMBEROFADAPTERS_GET) (int *);
typedef int (*ADL_ADAPTER_ADAPTERINFO_GET) (LPAdapterInfo, int);
typedef int (*ADL_ADAPTER_ACTIVE_GET) (int, int*);
typedef int (*ADL_OVERDRIVE5_TEMPERATURE_GET) (int, int, ADLTemperature*);
typedef int (*ADL_OVERDRIVE5_FANSPEED_GET) (int, int, ADLFanSpeedValue*);
typedef int (*ADL_OVERDRIVE5_FANSPEED_SET) (int, int, ADLFanSpeedValue*);
typedef int (*ADL_OVERDRIVE5_FANSPEEDTODEFAULT_SET) (int, int);
typedef int (*ADL_OVERDRIVE5_CURENTACTIVITY_GET) (int, ADLPMActivity *);
typedef int (*ADL_OVERDRIVE5_THERMALDEVICE_ENUM) (int, int, ADLThermalControllerInfo *);

static ADL_MAIN_CONTROL_CREATE           	adl_main_control_create;
static ADL_MAIN_CONTROL_DESTROY          	adl_main_control_destroy;
static ADL_ADAPTER_NUMBEROFADAPTERS_GET   	adl_adapter_numberofadapters_get;
static ADL_ADAPTER_ADAPTERINFO_GET        	adl_adapter_adapterinfo_get;
static ADL_ADAPTER_ACTIVE_GET             	adl_adapter_active_get;
static ADL_OVERDRIVE5_TEMPERATURE_GET     	adl_overdrive5_temperature_get;
static ADL_OVERDRIVE5_FANSPEED_GET       	adl_overdrive5_fanspeed_get;
static ADL_OVERDRIVE5_FANSPEED_SET        	adl_overdrive5_fanspeed_set;
static ADL_OVERDRIVE5_FANSPEEDTODEFAULT_SET adl_overdrive5_fanspeedToDefault_set;
static ADL_OVERDRIVE5_CURENTACTIVITY_GET    adl_overdrive5_currentActivity_get;
static ADL_OVERDRIVE5_THERMALDEVICE_ENUM    adl_overdrive5_thermaldevice_enum;

void amd_cleanup();
int init();
void set_default_fanspeed(int devNumber);
double set_fanspeed(int devNumber, unsigned int dw_fanSpeed);
double get_fanspeed(int devNumber, bool rpm);
double get_temp(int devNumber);
int get_gpu_activity(int devNumber);
void *getprocaddress(void *plibrary, const char * name);
void __stdcall *adl_main_memory_alloc(int isize);


namespace Ui {
class Widget;
}

class Widget : public QWidget
{
    Q_OBJECT
    
public:
    explicit Widget(QWidget *parent = 0);
    ~Widget();
    
private slots:
    void on_pushButton_2_clicked();
    void on_dial_valueChanged(int value);
    void on_comboBox_currentIndexChanged(int index);

protected:
    void timerEvent(QTimerEvent *event)
    {
        dTemp = get_temp(iDevice);
        dFanSpeed = get_fanspeed(iDevice, true);
        gpuActivityPercent = get_gpu_activity(iDevice);
        setInt1((int)dTemp);
        setInt2((int)dFanSpeed);
        setInt4(gpuActivityPercent);
    }

signals:
    void setInt1(int); // Set temperarue to LCD
    void setInt2(int); // Set RPM to LCD
    void setInt3(int); // Set ned percent RPM to LCD
    void setInt4(int); // Set GPU ACTIVITY to LCD
    void setDialValue(int);

private:
    Ui::Widget *ui;

    int iDeviceNumber;
    int iNeedFanSpeed;

    int iDevice;

    double dFanSpeed;
    double dTemp;

    int gpuActivityPercent;

    bool bAmdActive;
};



#endif // WIDGET_H
